# coding: utf-8
from typing import Union

from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon, QColor
from PySide6.QtWidgets import QVBoxLayout
from qfluentwidgets import BodyLabel, IconWidget, FluentIconBase, setFont

from components import CustomCardWidget


class TypeItemCard(CustomCardWidget):
    def __init__(self, icon: Union[str, QIcon, FluentIconBase], name: str, content: str, parent=None):
        super().__init__(parent)
        self.verticalLayout = QVBoxLayout(self)
        self.iconLabel = IconWidget(self)
        self.nameLabel = BodyLabel(self)
        self.contentLabel = BodyLabel(self)

        setFont(self.nameLabel, 16)
        setFont(self.contentLabel, 12)
        setFont(self.contentLabel, 14)
        self.iconLabel.setFixedSize(64, 64)
        self.contentLabel.setWordWrap(True)
        self.contentLabel.setTextColor(QColor('#adb5bd'), QColor('#ced4da'))
        self.contentLabel.setAlignment(Qt.AlignmentFlag.AlignHCenter)

        self.verticalLayout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
        self.verticalLayout.setSpacing(11)
        self.verticalLayout.setContentsMargins(20, 20, 20, 20)
        self.verticalLayout.addWidget(self.iconLabel, 0, Qt.AlignmentFlag.AlignHCenter)
        self.verticalLayout.addWidget(self.nameLabel, 0, Qt.AlignmentFlag.AlignHCenter)
        self.verticalLayout.addWidget(self.contentLabel, 0)

        if icon:
            self.setIcon(icon)
        if name:
            self.setName(name)
        if content:
            self.setContent(content)

    def setIcon(self, icon: Union[str, QIcon, FluentIconBase]):
        self.iconLabel.setIcon(icon)

    def setName(self, name: str):
        self.nameLabel.setText(name)

    def setContent(self, content: str):
        self.contentLabel.setText(content)
